<template>
	<view class="page">
		<flowbefore :beflows="beflows" :status="status" :isBtnClick="isBtnClicks" @save="save" @submit="submit" :statusType="statusType">
			<template>
				<view class="padding-bottom-100">
					<form class="flowform">
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>流程标题</label><text style="color: red;">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.flowTitle" name="flowTitle" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>单号编号</label></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.billNo" name="billNo" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="flowUrgent">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>紧急程度</label><text style="color: red;">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.flowUrgent" name="flowUrgent" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup">
								<view class="labletitle"><label>填表日期</label></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.fillFromDate" name="fillFromDate"/>
								</view>
							</view>
						</view>
						<view class="formlist inputtext margin-top-20">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>员工姓名</label></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.fullName" name="fullName" placeholder="输入姓名" :disabled="disabled"/>
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>员工部门</label></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.department" name="department" placeholder="输入部门" :disabled="disabled"/>
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>员工职务</label></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.position" name="position" placeholder="输入职务" :disabled="disabled"/>
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>赏罚金额</label><text style="color: red;">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="reward.rewardPun" name="rewardPun" placeholder="输入赏罚金额" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist">
							<view class="formgroup  padding-17">
								<view class="labletitletar"><label>赏罚原因</label><text style="color: red;">*</text></view>
								<view class="controlvalue  uni-textarea">
									<textarea v-model="reward.reason" name="reason" maxlength="500" placeholder="输入" :disabled="disabled"/>
								</view>
							</view>
						</view>
					</form>
					<view class="height-100"></view>
				</view>
			</template>
		</flowbefore>
		<w-picker :mode="mode" :pickerList="pickerList" ref="picker" :isSearchShow="isSearchShow"></w-picker>
	</view>
</template>

<script>
	import jnpf from '@/common/js/jnpf.js'
	import helper from '@/common/js/helper.js'
	import graceChecker from '@/common/js/graceChecker.js'
	import wPicker from '@/components/w-picker/w-picker.vue'
	import flowbefore from '@/components/work/flow-before.vue'
	let formRule=[
			{name:"flowTitle",checkType:"notnull",checkRule:"",errorMsg:"输入标题"},
			{name:"flowUrgent", checkType : "notnull", checkRule:"",  errorMsg:"选择紧急程度"},
			{name:"rewardPun", checkType : "money", checkRule:"",  errorMsg:"输入合格罚金"},
			{name:"reason", checkType : "notnull", checkRule:"",  errorMsg:"输入赏罚原因"},
		];
	export default {
		data() {
			return {
				statusType: null,
				mode:'',//底部弹窗分类
				isSearchShow:false,
				disabled:false,//启用
				status:'',//流程状态
				beflows:{
					operstate:"",
					processId:''
				},
				reward: {
					billNo: '',
					flowUrgent: '',
					flowTitle: jnpf.userInfo().realName+'的行政赏罚单',
					fillFromDate:helper.toDate(new Date, 'yyyy-MM-dd'),
					fullName:'',
					department:'',
					position:'',
					rewardPun:'0',
					reason:''
				},
				isBtnClicks:false,
				pickerList:[],
				urgentList:[{
					label: "普通",
					value:"1"
				},
				{
					label: "重要",
					value:"2"
				},
				{
					label: "紧急",
					value:"3"
				}],
			}
		},
		onLoad(e) {
			
			/* 工作区进入状态 */
			let statusType = uni.getStorageSync("type")
			this.statusType = statusType
			/* 工作区进入状态 End*/
			
			let flowInfo= JSON.parse(e.flowInfo);
			this.beflows.operstate=flowInfo.operstate;
			if(flowInfo.operstate =='add'){
				
				this.reward.flowId=flowInfo.id;
				this.status = 0;
				// this.status = flowInfo.operstate;
				this.reward.flowUrgent = helper.getSpinnerNew(this.urgentList,'1');
				helper.ajax({
					url: '/api/System/BillRule/BillNumber/WF_RewardPunishmentNo',
					success: res => {
						this.reward.billNo=res.data.data;
					}
				});
			}
			if(flowInfo.operstate=='info'){
				this.disabled=flowInfo.disabled;
				this.beflows.processId=flowInfo.id;
				this.status=flowInfo.status;
				// console.log(this.status)
				helper.ajax({
					url: '/api/WorkFlowForm/RewardPunishment/' + flowInfo.id,
					success: res => {
						let _reward=res.data.data;
						this.reward = _reward;
						this.reward.flowUrgent=helper.getSpinnerNew(this.urgentList,_reward.flowUrgent);
						this.reward.fillFromDate=helper.toDate(_reward.fillFromDate, 'yyyy-MM-dd');
					}
				});
			}
		},
		methods: {
			flowUrgent(e) {
				if(!this.disabled){
					this.pickerList = this.urgentList;
					this.mode="selector";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.reward.flowUrgent = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			submit(e){
				let formData=this.reward;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return;
				}
				this.isBtnClicks=true;
				formData.flowUrgent=helper.setSpinnerNew(this.urgentList,formData.flowUrgent);
				formData.status = '0';
				let method = "POST";
				let url = "/api/WorkFlowForm/RewardPunishment";
				if(formData.id){
					method = "PUT";
					url=url+"/"+formData.id
				}
				formData.fillFromDate = Date.parse(formData.fillFromDate);
				helper.ajax({
					url: url,
					method:method,
					contentType: "application/json",
					data:formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate=='add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
			save(e){
				let formData=this.reward;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return;
				}
				this.isBtnClicks=true;
				formData.flowUrgent=helper.setSpinnerNew(this.urgentList,formData.flowUrgent);
				formData.status = '1';
				let method = "POST";
				let url = "/api/WorkFlowForm/RewardPunishment";
				if(formData.id){
					method = "PUT";
					url=url+"/"+formData.id
				}
				formData.fillFromDate = Date.parse(formData.fillFromDate);
				helper.ajax({
					url: url,
					method:method,
					contentType: "application/json",
					data:formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate=='add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
		},
		components: {
			wPicker,
			flowbefore,
		}
	}
</script>

<style>
</style>
